﻿using JESAI.Application.Abstractions.Admin;
using JESAI.Application.Abstractions.Admin.Dtos.Dict;
using JESAI.Application.Abstractions.Admin.Dtos.Role;
using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Service.Admin;
using JESAI.Framework.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JESAI.Platform.WebApi.Controllers.Admin
{
    [ApiController]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class DictController : ControllerBase
    {
        private readonly IDictService _dictService;

        public DictController(IDictService dictService)
        {
            _dictService = dictService;
        }

        /// <summary>
        /// 设置字典信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/Dict/SetDict")]
        public async Task<BaseOutput> SetDict([FromBody] SetDictInput input)
        {
            await _dictService.UpdateOrInsert(input);

            return new BaseOutput { };
        }

        /// <summary>
        /// 删除字典
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet("/Dict/DeleteDicts")]
        public async Task<BaseOutput> DeleteDicts(string[] ids)
        {
            await _dictService.DeleteDicts(ids);
            return new BaseOutput { };
        }

        [HttpGet("/Dict/DeleteDict")]
        public async Task<BaseOutput> DeleteDict(string id)
        {
            await _dictService.DeleteDict(id);
            return new BaseOutput { };
        }

        /// <summary>
        /// 查询字典列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("/Dict/QueryPageDicts")]
        public async Task<BasePageOutput<List<QueryDictDto>>> QueryPageDicts([FromQuery] QueryDictPageInput input)
        {
            var result = await _dictService.QueryPageDicts(input);
            return result;
        }
    }
}
